﻿using System;
using System.Collections.Generic;

namespace ThresholdAssistant.Tools.Extensions
{
    /// <summary>
    /// IEnumerable扩展类
    /// </summary>
    public static class EnumerableExtensions
    {
        /// <summary>
        ///迭代遍历选项
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static IEnumerable<T> Add<T>(this IEnumerable<T> enumerable, T value)
        {
            foreach (var cur in enumerable)
            {
                yield return cur;
            }
            yield return value;
        }

        /// <summary>
        /// ForEach扩展方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="action"></param>
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (T item in source)
            {
                action(item);
            }
        }
    }
}